<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //倒计时
        function cutdown(time) {
            var nowtime = +new Date();
            var usertime = +new Date(time); //返回用户输入的毫秒数
            var times = (usertime - nowtime) / 1000; //秒
            var m = parseInt(times % 60); //当前秒
            m = m < 10 ? "0" + m : m;
            var f = parseInt(times / 60 % 60); //分
            f = f < 10 ? "0" + f : f;
            var h = parseInt(times / 60 / 60 % 24); //小时
            h = h < 10 ? "0" + h : h;
            var d = parseInt(times / 60 / 60 / 24); //天
            d = d < 10 ? "0" + d : d;
            return d + "天" + h + "小时" + f + "分" + m + "秒";
        }
        console.log(cutdown("2021-4-30 21:00:00"));

        function cut(time) {
            var nowtime = +new Date();
            var inputtime = +new Date(time);
            var times = (inputtime - nowtime) / 1000;
            var d = parseInt(times / 60 / 60 / 24);
            d = d < 10 ? "0" + d : d;
            var h = parseInt(times / 60 / 60 % 24);
            h = h < 10 ? "0" + h : h;
            var f = parseInt(times / 60 % 60);
            f = f < 10 ? "0" + f : f;
            var m = parseInt(times % 60);
            m = m < 10 ? "0" + m : m;
            return d + "天" + h + "时" + f + "分" + m + "秒"
        }
        console.log(cut("2021-4-30 22:00:00"));
    </script>
</head>

<body>

</body>

</html>